#ifndef TICKER_DATA_CLOCK_H
#define TICKER_DATA_CLOCK_H

#include "ticker_api.h"

class TickerDataClock {
public:
    constexpr TickerDataClock(const ticker_data_t *ticker) : _ticker(ticker)
    {
    }
    static const bool is_steady = false;
    void set_handler(ticker_event_handler handler)
    {
        return ticker_set_handler(_ticker, handler);
    }
    void remove_event(ticker_event_t *obj)
    {
        ticker_remove_event(_ticker, obj);
    }
    void insert_event(ticker_event_t *obj, uint64_t timestamp, uint32_t id)
    {
        ticker_insert_event_us(_ticker, obj, timestamp, id);
    }
    uint64_t now() const
    {
        return ticker_read_us(_ticker);
    }
    int get_next_timestamp(uint64_t *timestamp) const
    {
        us_timestamp_t t;
        int ret = ticker_get_next_timestamp_us(_ticker, &t);
        *timestamp = t;
        return ret;
    }
    void suspend()
    {
        ticker_suspend(_ticker);
    }
    void resume()
    {
        ticker_resume(_ticker);
    }

    constexpr const ticker_data_t *operator->() const
    {
        return _ticker;
    }
    constexpr operator const ticker_data_t *() const
    {
        return _ticker;
    }

private:
    const ticker_data_t *const _ticker;
};

inline uint64_t get_time_point(const ticker_event_t &event)
{
    return event.timestamp;
}

#endif